package top.abrsm.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import top.abrsm.entity.AreaEntity;

import java.util.List;

@Mapper
public interface AreaMapper extends BaseMapper<AreaEntity> {

    @Select (value = "<script>select ai.*,aii.areaName AS parentAreaName from area_info ai, area_info aii <where> ai.parentId=aii.id and ai.level=#{level} <if test='parentId!=null'> and ai.parentId=#{parentId}</if></where></script>")
    List<AreaEntity> queryChild (String parentId, Integer level);

    @Select (value = "<script>select COUNT(1) from area_info ai, area_info aii <where> ai.parentId=aii.id and ai.level=#{level} <if test='parentId!=null'> and ai.parentId=#{parentId}</if></where></script>")
    Integer queryCount (String parentId, Integer level);

}
